#include <iostream>

using namespace std;

struct Edge
{
    int bv, ev;
    double w;
};

Edge edge[ 75 ];
double sum;
int Point[ 26 ], n, e;

int Kruscal_F( int Point[], int v )
{
    int i = v;
    while ( Point[ i ] > 0 )
        i = Point[ i ];
    return i;
}

void Kruscal( )
{
    int i, j, v1, v2;
    for ( i = 0; i < n; i++ )
        Point[ i ] = 0;
    i = j = 0;
    while ( j < n - 1 && i < e )
    {
        v1 = Kruscal_F( Point, edge[ i ].bv );
        v2 = Kruscal_F( Point, edge[ i ].ev );
        if ( v1 != v2 )
        {
            sum += edge[ i ].w;
            Point[ v1 ] = v2;
            j++;
        }
        i++;
    }
}

void sort( )
{
    int i, j, k, tmp;
    double tmp2;
    for ( i = 0; i < e; i++ )
    {
        k = i;
        for ( j = i + 1; j < e; j++ )
            if ( edge[ k ].w > edge[ j ].w ) k = j;
        tmp = edge[ i ].bv; edge[ i ].bv = edge[ k ].bv; edge[ k ].bv = tmp;
        tmp = edge[ i ].ev; edge[ i ].ev = edge[ k ].ev; edge[ k ].ev = tmp;
        tmp2 = edge[ i ].w; edge[ i ].w = edge[ k ].w; edge[ k ].w = tmp2;
    }
}

int main( )
{
    int i, j, num;
    double cost;
    char ch, ch1;
    while ( cin >> n )
    {
        if ( n == 0 ) break;
        sum = e = 0;
        for ( i = 0; i < n - 1; i++ )
        {
            cin >> ch >> num;
            for ( j = 0; j < num; j++ )
            {
                cin >> ch1 >> cost;
                edge[ e ].bv = ch - 65;
                edge[ e ].ev = ch1 - 65;
                edge[ e ].w = cost;
                e++;
            }
        }
        sort( );
        Kruscal( );
        cout << sum << endl;
    }
    return 0;
}

